from rest_framework import serializers
from .models import SPUSpecification,SPU,SpecificationOption,SKUSpecification
class SpuSSer(serializers.ModelSerializer):
    spu_name = serializers.SerializerMethodField(read_only=True)
    def get_spu_name(self,obj):
        return obj.spu.name
    class Meta:
        model = SPUSpecification
        fields = '__all__'


class SkuSSer(serializers.ModelSerializer):
    spec_name = serializers.SerializerMethodField(read_only=True)
    option_name = serializers.SerializerMethodField(read_only=True)
    sku_name = serializers.SerializerMethodField(read_only=True)
    def get_spec_name(self,obj):
        return obj.spec.name
    def get_option_name(self,obj):
        return obj.specificationoption.value
    def get_sku_name(self,obj):
        return obj.good.name
    class Meta:
        model = SKUSpecification
        fields = '__all__'


class OptionSer(serializers.ModelSerializer):
    spec_name = serializers.SerializerMethodField(read_only=True)
    def get_spec_name(self,obj):
        return obj.spec.name
    def get_spu_name(self,obj):
        return obj.spu.name
    class Meta:
        model = SpecificationOption
        fields = '__all__'